package com.imcode.exceptiondemo;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ExceptionDemo04 {

    public static void main(String[] args) {
        //test(0);
        test01();
    }

    public static void test01() {
        Scanner sc = null;
        try {
            sc = new Scanner(new File("D:\\data2.txt"));
            while (sc.hasNextLine()) {
                System.out.println(sc.nextLine());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (sc != null) {
                sc.close();
            }
        }
    }


    public static void test(int i) {
        int r;
        try {
            r = 100 / i;
        } catch (Exception e) {
            r = 0;
        }
        // 无论是否发生异常 finally中的代码都会执行，一般用于在程序结束之前释放系统资源
        finally {
            System.out.println("程序结束");
        }
        System.out.println(r);
    }


}
